package com.xhtt.modules.app.controller.inspection;

import com.xhtt.common.utils.Constant;
import com.xhtt.common.utils.R;
import com.xhtt.modules.inspection.dto.InsClassesDTO;
import com.xhtt.modules.inspection.service.IInsClassesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 巡检-排班管理
 * </p>
 *
 * @author xj
 * @since 2019-01-29
 */
@RestController
@RequestMapping("app/ins-classes")
@Api(value = "巡检-排班管理", tags = "巡检-排班管理")
public class InsClassesController {

    @Autowired
    private IInsClassesService insClassesService;

    @PostMapping(value = "/add")
    @ApiOperation("新增排班(web)")
    public R add(@RequestBody InsClassesDTO insClassesDTO) {
        insClassesService.addOrUpdate(insClassesDTO);
        return R.ok();
    }

    @GetMapping(value = "/getEnabledList")
    @ApiOperation("获取所有已排班集合(web)")
    public R getEnabledList(@RequestParam("month") String month) {
        return R.ok().put(Constant.DATA, insClassesService.getAll(month));
    }

    @GetMapping(value = "/getDetail")
    @ApiOperation("获取排班与任务详情(web)")
    public R getDetail(@RequestParam String date) {
        return R.ok().put(Constant.DATA, insClassesService.getDetail(date));

    }

    @GetMapping(value = "/getAlreadyTaskAndClasses")
    @ApiOperation("获取排班并且已发布任务的日期集合(web)")
    public R getRedList(@RequestParam("month") String month) {

        Map<String, Object> result = new HashMap<>();
        result.put("morning", insClassesService.getMorning(month));
        result.put("night", insClassesService.getNight(month));

        return R.ok().put(Constant.DATA, result);
    }

}
